#include "myfilelog.hxx"
#include "loghelper.hxx"
#include "audioplayer.hxx"

//AudioPlayer::AudioPlayer()
//:	_bits_per_sample(0),
//	_samples_per_sec(0),
//	_block_nb(0),
//	_block_size(0),
//	_current_block(0),
//	_free_block_count(_block_nb),
//	_channel_nb(0),
//	_current_pos(-1),
//	_mutex_on_count(),
//	_filelog(NULL)
//{}
AudioPlayer::AudioPlayer(tUInt32 bits_sample,tUInt32 sample_sec,tUInt32 block_nb,tUInt32 block_size,tUInt32 channel_nb,FileLog* filelog)
:	_bits_per_sample(bits_sample),
	_samples_per_sec(sample_sec),
	_block_nb(block_nb),
	_block_size(block_size),_current_block(0),_free_block_count(_block_nb),
	_channel_nb(channel_nb),_mutex_on_count(),_filelog(filelog)
{}
AudioPlayer::~AudioPlayer()
{}
tInt32 AudioPlayer::IncrFreeBlockCount(void)
{
	tUInt32 ret = 0;

	_mutex_on_count.Lock();

	if (_free_block_count < _block_nb)
		_free_block_count++;
	else
		ResetPlayer();

	ret = _free_block_count;

	_mutex_on_count.Unlock();

	return ret;
}
tInt32 AudioPlayer::DecrFreeBlockCount(void)
{
	tUInt32 ret = 0;

	_mutex_on_count.Lock();
	
	if (_free_block_count>0)
		ret = --_free_block_count;
	else
		ret = -1;

	_mutex_on_count.Unlock();

	return ret;
}
